package com.chenc.unitdemo.config;

import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import net.minidev.json.JSONObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;

import java.security.KeyPair;
import java.security.interfaces.RSAPublicKey;

/**
 * @ClassName
 * @Describtion:
 * @Author:Chenc
 * @Date:2024/1/12 15:05
 * @Version 1.0
 */
@Configuration
public class Oauth2ServerConfig {

    @Bean
    public KeyPair keyPair() {
        //从classpath下的证书中获取秘钥对
        //keytool -genkeypair -alias jwt -validity 365000 -keyalg RSA -dname "CN=jwt,OU=jtw,O=jwt,L=zurich,S=zurich, C=CH" -keypass 123456 -keystore jwt.jks -storepass 123456
        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "123456".toCharArray());
        return keyStoreKeyFactory.getKeyPair("jwt", "123456".toCharArray());
    }

}
